package com.sx.pipeline.ui.supply.frag

import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.view.BLTextView
import com.sx.pipeline.R
import com.sx.pipeline.app.config.ReleaseSupplyType
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.repos.http.res.ReleaseSupplyVo

/**
 * @Author：YY
 * @Date：2022/2/10
 * @Describe: 任务列表适配器
 */
class ReleaseSupplyListAdapter(
) : BaseQuickAdapter<ReleaseSupplyVo, BaseViewHolder>(
    R.layout.item_release_supply
) {
    /**
     * 取消发布
     */
    var cancelReleaseCallback: ((Int) -> Unit)? = null

    /**
     * 取消供应
     */
    var cancelSupplyCallback: ((Int) -> Unit)? = null


    /**
     * 删除任务
     */
    var deleteTaskCallback: ((Int) -> Unit)? = null
    override fun convert(holder: BaseViewHolder, item: ReleaseSupplyVo) {
        //任务时间
        holder.setText(R.id.tv_time,item.createTime)
        //任务标题
        holder.setText(R.id.tv_title,item.title)
        //供应时间
        holder.setText(R.id.tv_supply_time,"供应时间：${item.startTime}-${item.endTime}")
        //供应服务区域
        holder.setText(R.id.tv_supply_address,"供应服务区域：${item.addressDetail}")
        //供应负责人
        holder.setText(R.id.tv_contact,"供应负责人：${item.contact}")
        //供应联系方式
        holder.setText(R.id.tv_contact_num,"联系方式：${item.contactPhone}")
        if (item.payMoney.toInt()!=0){
            //管币价格
            holder.setText(R.id.tv_money,""+item.payMoney)
            holder.setVisible(R.id.tv_money,true)
        }else{
            holder.setGone(R.id.tv_money,true)
        }

        when (item.status) {
            //待审核
            ReleaseSupplyType.PENDING_REVIEW.code -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_pending_review))

                holder.setText(R.id.tv_action, context.getString(R.string.txt_cancel_release))
                holder.setVisible(R.id.tv_action,true)
                holder.setGone(R.id.tv_delete,true)
            }
            //待询价
            ReleaseSupplyType.TO_BE_INQUIRED.code -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_be_inquired))

                holder.setText(R.id.tv_action, context.getString(R.string.txt_cancel_inquire))
                holder.setVisible(R.id.tv_action,true)
                holder.setGone(R.id.tv_delete,true)
            }
            //已询价
            ReleaseSupplyType.INQUIRED.code -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_inquired))

                holder.setText(R.id.tv_action, context.getString(R.string.txt_view_inquire))
                holder.setVisible(R.id.tv_action,true)
                holder.setGone(R.id.tv_delete,true)
            }
            //已取消
            ReleaseSupplyType.CANCELLED.code -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_cancelled))

                holder.setText(R.id.tv_delete, context.getString(R.string.txt_delete_inquire))
                holder.setVisible(R.id.tv_delete, true)
                holder.setGone(R.id.tv_action, true)
            }
            //已过期
            ReleaseSupplyType.EXPIRED.code -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_expired))

                holder.setText(R.id.tv_delete, context.getString(R.string.txt_delete_inquire))
                holder.setVisible(R.id.tv_delete, true)
                holder.setGone(R.id.tv_action, true)
            }
            //已驳回
            ReleaseSupplyType.REJECTED.code -> {
                holder.setText(R.id.tv_status,context.getString(R.string.txt_rejected))

                holder.setText(R.id.tv_delete, context.getString(R.string.txt_delete_inquire))
                holder.setText(R.id.tv_action, context.getString(R.string.txt_rejection_reason))
                holder.setVisible(R.id.tv_delete, true)
                holder.setVisible(R.id.tv_action, true)
            }


        }

        holder.getView<BLTextView>(R.id.tv_action).setOnClickListener {
            when (item.status) {
                //取消发布
                ReleaseSupplyType.PENDING_REVIEW.code -> cancelReleaseCallback?.invoke(item.id)
                //取消供应
                ReleaseSupplyType.TO_BE_INQUIRED.code -> cancelSupplyCallback?.invoke(item.id)
                //查看询价
                ReleaseSupplyType.INQUIRED.code -> RouteManager.Mine.intentTViewInquiry(item.id)
                //已驳回 跳转详情查看拒绝原因
                ReleaseSupplyType.REJECTED.code -> RouteManager.Mine.intentToSupplyDetail(item.id)
            }
        }
        holder.getView<BLTextView>(R.id.tv_delete).setOnClickListener {
            when (item.status) {
                //删除任务
                ReleaseSupplyType.EXPIRED.code,ReleaseSupplyType.CANCELLED.code, ReleaseSupplyType.REJECTED.code -> deleteTaskCallback?.invoke(item.id)
            }
        }
    }
}